package com.gr.staffpm.pages.projects;

import java.util.ArrayList;
import java.util.List;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.PageParameters;
import org.apache.wicket.extensions.markup.html.tabs.AbstractTab;
import org.apache.wicket.extensions.markup.html.tabs.ITab;
import org.apache.wicket.extensions.markup.html.tabs.TabbedPanel;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.wicketstuff.annotation.mount.MountPath;
import org.wicketstuff.annotation.strategy.MountHybrid;

import com.gr.staffpm.StaffPMWebPage;
import com.gr.staffpm.datatypes.Project;
import com.gr.staffpm.projects.service.ProjectService;

@MountHybrid
@MountPath(path = "secure/ViewProject")
public class ViewProject extends StaffPMWebPage {

    @SpringBean(name = "projectService")
    private ProjectService projectService;
    private final Project p;

    public ViewProject(PageParameters parameters) {

        super();
        this.p = projectService.getProject(parameters.getInt("id"));
        super.onBeforeRender();

        setDefaultModel(new Model<String>("tabPanel"));

        add(new Label("projectName", "Project: " + p.getProjectName()));

        List<ITab> tabs = new ArrayList<ITab>();

        tabs.add(new AbstractTab(new Model<String>("Summary")) {

            private static final long serialVersionUID = 1L;

            @Override
            public Panel getPanel(String id) {
                return new SummaryTabPanel(id, p);
            }
        });

        tabs.add(new AbstractTab(new Model<String>("Tasks")) {

            private static final long serialVersionUID = 1L;

            @Override
            public Panel getPanel(String id) {
                return new TasksTabPanel(id, p);
            }
        });

        add(new TabbedPanel("tabs", tabs).add(new AttributeModifier("class", true, getDefaultModel())));
    }

    public Project getProject() {
        return p;
    }

    @Override
    public String getTitle() {
        return "Project: " + p.getProjectName() + " - StaffPM";
    }

}
